package com.yunsc.shop.controller.order;

import com.yunsc.common.utils.PageResult;
import com.yunsc.common.utils.Result;
import com.yunsc.common.utils.SecurityUtil;
import com.yunsc.common.validator.ValidationGroups;
import com.yunsc.order.dto.ApplyOrderRefundDTO;
import com.yunsc.order.dto.OrderRefundDTO;
import com.yunsc.order.sevice.YunscOrderRefundService;
import com.yunsc.order.sevice.YunscOrderService;
import com.yunsc.order.vo.OrderRefundVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @version: 1.0
 * @Author: adan
 * @description:
 * @date: 2024-05-20 22:29
 */
@Api(tags = "订单售后接口")
@RestController
@RequestMapping("refund")
public class OrderRefundController {
    @Resource
    private YunscOrderRefundService orderRefundService;
    @Resource
    private YunscOrderService orderService;
    
    @ApiOperation(value = "订单售后列表", tags = "订单售后列表")
    @GetMapping("/list")
    public Result<?> queryRefundOrder(@RequestParam("state") Integer state, @RequestParam("page") Integer page) {
        // 根据dataType和page获取用戶订单列表数据
        Integer userId = SecurityUtil.getCurrentUserIdEx();
        PageResult<OrderRefundVO> refundOrder = orderRefundService.queryUserRefundOrder(state, page, userId);
        return Result.resultPageList(refundOrder);
    }


    @GetMapping("/detail")
    public Result<?> queryRefundOrderDetail2(@RequestParam("orderRefundId") Integer orderRefundId) {
        // 根据dataType和page获取用戶订单列表数据
        Integer userId = SecurityUtil.getCurrentUserIdEx();
        OrderRefundVO refundOrder = orderRefundService.queryUserRefundOrderDetail(orderRefundId);
        Map<String, Object> map = new HashMap<>();
        map.put("detail", refundOrder);
        return Result.ok(map);
    }

    //
    // // audit
    // @PostMapping("/audit")
    // public R auditOrderRefund(@RequestBody @Validated(ValidationGroups.Update.class) OrderRefundParamsDto param) {
    //     orderRefundService.auditOrderRefund(param);
    //     return R.ok();
    // }
    //
    // // order/refund/goods
    // @GetMapping("/goods")
    // public R queryRefundOrderGoods(@RequestParam("orderGoodsId") Integer orderGoodsId) {
    //     // 根据dataType和page获取用戶订单列表数据
    //     Integer userId = SecurityUtil.getUserId();
    //     YoshopOrderGoodsEntity goods = orderService.queryOrderGoodsById(orderGoodsId);
    //     Map<String, Object> map = new HashMap<>();
    //     map.put("goods", goods);
    //     return R.ok().put("data", map);
    // }
    //
    @ApiOperation(value = "/order/refund/goods/apply", tags = "申请售后")
    @PostMapping("/apply")
    public Result<?> applyRefundOrderGoods(@RequestBody @Validated(ValidationGroups.Insert.class) ApplyOrderRefundDTO param) {
        // 根据dataType和page获取用戶订单列表数据
        Integer userId = SecurityUtil.getCurrentUserIdEx();
        orderRefundService.applyOrderRefund(param, userId);
        return Result.ok("申请成功");
    }

    @ApiOperation(value = "/order/refund/delivery", tags = "提交用户发货信息")
    @PostMapping("/delivery")
    public Result<?> refundOrderDelivery(@RequestBody @Validated(ValidationGroups.Update.class) OrderRefundDTO param) {
        // 根据dataType和page获取用戶订单列表数据
        Integer userId = SecurityUtil.getCurrentUserIdEx();
        orderRefundService.refundOrderDelivery(param, userId);
        return Result.ok("提交成功");
    }
}
